<!DOCTYPE html>
<html lang="en">
<head xmlns:th="http://www.thymeleaf.org">
    <meta charset="UTF-8">
    <title>学生成绩管理系统</title>
    <script src="/js/jquery-3.6.0.min.js"></script>
    <link rel="stylesheet" href="/css/bootstrap.min.css">

    <link rel="stylesheet" href="/plugins/bootstraptable/bootstrap-table.min.css">
</head>
<body>

<!--教师权限-->
<div class="container-fluid" >
    <div style="margin: 20px 20px">
        <font size="5px">页面切换：</font>
        <a href="/student/list"><font size="4px">学生表&nbsp&nbsp&nbsp&nbsp</font></a>
        <a href="/teacher/tlist"><font size="4px">教师表&nbsp&nbsp&nbsp&nbsp</font></a>
        <a href="/course/clist"><font size="4px">授课表&nbsp&nbsp&nbsp&nbsp</font></a>
        <a href="/login/user"><font size="4px" style="margin-left:950px">退出登录</font></a>
    </div>

    <h2 align =center>科目成绩表</h2>

    <form class="form-inline">
        <div class="form-group">
            <input type="text" class="form-control" id="searchName" name="searchName" placeholder="请输入学生名字">
            <button type="button" class="btn btn-default btn-primary" onclick="searchSc();">查询成绩</button>
        </div>
        <button style="margin-left: 25px" type="button" class="btn btn-primary btn-primary" data-toggle="modal" data-target="#myModal" onclick="preAdd();">
            <font size="3px">新增学生成绩</font>
        </button>
    </form>

    <table class="table table-bordered table-striped table-hover" style="table-layout:fixed;" id="scTable">
    </table>
</div>

<div class="modal fade" tabindex="-1" role="dialog" id="myModal" >
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <form id="scForm">
                    <input hidden="hidden" id="id" name="id"/>
                    <div class="form-group">
                        <label for="sno">学号</label>
                        <input type="text" class="form-control" id="sno" name="sno" placeholder="学号">
                    </div>
                    <div class="form-group">
                        <label for="name">姓名</label>
                        <input type="text" class="form-control" id="name" name="name" placeholder="姓名">
                    </div>
                    <div class="form-group">
                        <label for="cno">课程号</label>
                        <input type="cno" class="form-control" id="cno" name="cno" placeholder="课程号">
                    </div>
                    <div class="form-group">
                        <label for="cname">课程名</label>
                        <input type="cname" class="form-control" id="cname" name="cname" placeholder="课程名">
                    </div>
                    <div class="form-group">
                        <label for="score">成绩</label>
                        <input type="text" class="form-control" id="score" name="score" placeholder="成绩">
                    </div>
                </form><!--表单结束-->
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" onclick="saveSc();">保存</button>
            </div>
        </div>
    </div>
</div>

    <script src="/js/bootstrap.min.js"></script>
    <script src="/plugins/bootstraptable/bootstrap-table.min.js"></script>
    <script src="/plugins/bootstraptable/locale/bootstrap-table-zh-CN.min.js"></script>
    <script type="text/javascript">

        //查询
        function searchSc(){
            $('#scTable').bootstrapTable("destroy");
            loadTable();
        }
        // function searchSc(){
        //     var name=$("#name1").val();
        //     console.log("name:"+name)
        //     getdata(name);
        //     return false;
        // }
        // function getdata(name){
        //     var url="/webapi/sc/findScByNameLike";
        //     if(name!=null && name!=""){
        //         url +="?name="+name;
        //     }
        //     $.ajax({
        //         url:url
        //     }).done(function (rs) {
        //         var len = rs.length;
        //         var htmlStr = "";
        //         for (var i = 0; i < len; i++) {
        //             var item = rs[i];
        //             htmlStr += "<tr>"
        //                 + "<td>" + item.id + "</td>"
        //                 + "<td>" + item.sno + "</td>"
        //                 + "<td>" + item.name + "</td>"
        //                 + "<td>" + item.cno+ "</td>"
        //                 + "<td>" + item.cname + "</td>"
        //                 + "<td>" + item.score + "</td>"
        //                 +"<td> <a href='#' onclick='editSc("+item.id+");'>编辑</a>  <a href='#' onclick='deleteSc("+item.id+");'>删除</a></td>"
        //                 + "</tr>";
        //         }
        //         $("#scTb").html(htmlStr);
        //     })
        // }
        // $(function(){
        //     getdata();
        // });

        function  preAdd(){
            $("#id").val(0);//提示新增
            $("#id").val('');
            $("#sno").val('');
            $("#name").val('');
            $("#cno").val('');
            $("#cname").val('');
            $("#score").val('');
        }

        //新增或更新
        function saveSc(){
            var data=$("#scForm").serialize();
            var id=$("#id").val();
            if(id<1){
                //新增
                $.ajax({
                    url:"/webapi/sc/insert",
                    method:"post",
                    data:data
                }).done(function(){
                    $('#scTable').bootstrapTable("refresh");
                    $('#myModal').modal('hide')
                })
            }
            else{
                //更新
                $.ajax({
                    url:"/webapi/sc/update",
                    method:"put",
                    data:data
                }).done(function (){
                    $('#scTable').bootstrapTable("refresh");
                    $('#myModal').modal('hide')
                })
            }
        }

        //编辑
        function editSc(id){
            $.ajax({
                url:'/webapi/sc/get/'+id
            }).done(function (rs){
                $("#id").val(rs.id);
                $("#sno").val(rs.sno);
                $("#name").val(rs.name);
                $("#cno").val(rs.cno);
                $("#cname").val(rs.cname);
                $("#score").val(rs.score);
                $('#myModal').modal('show');
            })
            loadTable();
        }

        //删除
        function deleteSc(id){
            if(confirm("确认要删除该学生成绩信息?")){
                $.ajax({
                    url:'/webapi/sc/delete/'+id,
                    method:"delete"
                }).done(function(){
                    $('#scTable').bootstrapTable("refresh");//表格自动更新
                });
            }
        }

        function loadTable(){
            $('#scTable').bootstrapTable({
                url:'/webapi/sc/getByPage',
                striped:true,//true隔行变色效果
                pagination:true,//true在底部显示分页条
                singleSelect: false,//true禁止多选
                pageSize:5,//如果设置了分页，每条数据条数
                pageNumber:1,//如果设置了分页,首页页码
                sidePagination: "server",//设置在哪里进行分页，可选值为“client”
                queryParams:function (params){
                    var paraObj={
                        size: params.limit,
                        page:params.offset/params.limit,
                        sort:"id",
                        direct:"desc",
                        name:$("#searchName").val()
                    };
                    return paraObj;
                },
                columns:[{
                    field:'id',
                    title:'序号',
                    align : 'center'
                },{
                    field:'sno',
                    title:'学号',
                    align : 'center'
                },{
                    field:'name',
                    title:'姓名',
                    align : 'center'
                },{
                    field:'cno',
                    title:'课程号',
                    align : 'center'
                },{
                    field:'cname',
                    title:'课程名',
                    align : 'center',
                },{
                    field:'score',
                    title:'成绩',
                    align : 'center'
                },{
                    field: 'id',
                    title:'操作',
                    align : 'center',
                    formatter:function (value,row){
                        var e='<a href="#" onclick="editSc(\''
                            + row.id + '\')">编辑 </a>';
                        var f='<a href="#" onclick="deleteSc(\''
                            + row.id + '\')">删除</a>';
                        return e+f;
                    }
                }]
            });
        }//end of loadTable()
        $(function(){
            loadTable();
            $('#myModal').modal('hide')
        })
    </script>
</body>
</html>



